package com.filter;

/**
 * version 1.0.0
 * url访问记录
 * @author KKW
 * @date 2017/7/7.
 */
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class URLFilter implements Filter{

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req=(HttpServletRequest) servletRequest;
        HttpSession session=req.getSession();
        List<String> ls=(List<String>)session.getAttribute("URLS");
        if(ls!=null){
            ls.add(req.getRequestURI());
        }
        else {
            ls=new ArrayList<String>();
            ls.add(req.getRequestURI());
            session.setAttribute("URLS",ls);
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
